package com.neu.niuyuchao.servlet;

import com.neu.niuyuchao.service.MgrApproveService;
import com.neu.niuyuchao.service.UpdateStuDorService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "UpdateStuDorServlet", urlPatterns = {"/UpdateStuDorServlet.do"})
public class UpdateStuDorServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String[]allapp=request.getParameterValues("approveBox");

        String go_build=request.getParameter("go_build");
        String go_dor=request.getParameter("go_dor");
        String stu_id=request.getParameter("stu_id");
        String appro_id2=request.getParameter("appro_id");
         MgrApproveService mgr=new MgrApproveService();
        Map<String,Object> item=mgr.doFindStuDorId(go_build,go_dor);
        String dor_id=item.get("dor_id").toString();
        UpdateStuDorService up=new UpdateStuDorService();
            System.out.println(item);

        boolean flag=up.doUpdateStuDor(dor_id,stu_id);
        if(flag){
             mgr.doUpdateApplyStatusTwo(appro_id2);
            response.sendRedirect( request.getContextPath()+"/commons/success.jsp");
        }else{
            response.sendRedirect( request.getContextPath()+"/commons/fail.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
